package com.happy.cat.project.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.happy.cat.common.utils.StringUtils;
import com.happy.cat.common.utils.poi.ExcelUtil;
import com.happy.cat.framework.web.controller.BaseController;
import com.happy.cat.framework.web.domain.AjaxResult;
import com.happy.cat.framework.web.page.TableDataInfo;
import com.happy.cat.project.system.domain.UserLightStack;
import com.happy.cat.project.system.service.IUserLightStackService;
import com.happy.cat.framework.aspectj.lang.annotation.Log;
import com.happy.cat.framework.aspectj.lang.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 账号荧光棒明细Controller
 *
 * @author verne
 * @date 2020-08-12
 */
@AllArgsConstructor
@RestController
@RequestMapping("/system/userLightStack" )
@Api("账号荧光棒明细 API")
public class UserLightStackController extends BaseController {

    private final IUserLightStackService iUserLightStackService;

    /**
     * 查询账号荧光棒明细列表
     */
    @ApiOperation(value = "查询账号荧光棒明细列表",notes = "查询账号荧光棒明细列表",response = TableDataInfo.class)
    @PreAuthorize("@ss.hasPermi('system:userLightStack:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserLightStack userLightStack)
    {
        startPage();
        LambdaQueryWrapper<UserLightStack> lqw = new LambdaQueryWrapper<UserLightStack>();
        if (userLightStack.getType() != null){
            lqw.eq(UserLightStack::getType ,userLightStack.getType());
        }
        if (userLightStack.getSroce() != null){
            lqw.eq(UserLightStack::getSroce ,userLightStack.getSroce());
        }
        if (userLightStack.getCurrentSroce() != null){
            lqw.eq(UserLightStack::getCurrentSroce ,userLightStack.getCurrentSroce());
        }
        if (userLightStack.getChangeTime() != null){
            lqw.eq(UserLightStack::getChangeTime ,userLightStack.getChangeTime());
        }
        if (userLightStack.getAccountId() != null){
            lqw.eq(UserLightStack::getAccountId ,userLightStack.getAccountId());
        }
        if (userLightStack.getRewardGift() != null){
            lqw.eq(UserLightStack::getRewardGift ,userLightStack.getRewardGift());
        }
        if (userLightStack.getLuckDrawGift() != null){
            lqw.eq(UserLightStack::getLuckDrawGift ,userLightStack.getLuckDrawGift());
        }
        if (StringUtils.isNotBlank(userLightStack.getRemarks())){
            lqw.eq(UserLightStack::getRemarks ,userLightStack.getRemarks());
        }
        List<UserLightStack> list = iUserLightStackService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出账号荧光棒明细列表
     */
    @ApiOperation(value = "导出账号荧光棒明细列表",notes = "导出账号荧光棒明细列表",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userLightStack:export')" )
    @Log(title = "账号荧光棒明细" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(UserLightStack userLightStack) {
        LambdaQueryWrapper<UserLightStack> lqw = new LambdaQueryWrapper<UserLightStack>(userLightStack);
        List<UserLightStack> list = iUserLightStackService.list(lqw);
        ExcelUtil<UserLightStack> util = new ExcelUtil<UserLightStack>(UserLightStack. class);
        return util.exportExcel(list, "userLightStack" );
    }

    /**
     * 获取账号荧光棒明细详细信息
     */
    @ApiOperation(value = "获取账号荧光棒明细详细信息",notes = "获取账号荧光棒明细详细信息",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userLightStack:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iUserLightStackService.getById(id));
    }

    /**
     * 新增账号荧光棒明细
     */
    @ApiOperation(value = "新增账号荧光棒明细",notes = "新增账号荧光棒明细",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userLightStack:add')" )
    @Log(title = "账号荧光棒明细" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserLightStack userLightStack) {
        return toAjax(iUserLightStackService.save(userLightStack) ? 1 : 0);
    }

    /**
     * 修改账号荧光棒明细
     */
    @ApiOperation(value = "修改账号荧光棒明细",notes = "修改账号荧光棒明细",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userLightStack:edit')" )
    @Log(title = "账号荧光棒明细" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserLightStack userLightStack) {
        return toAjax(iUserLightStackService.updateById(userLightStack) ? 1 : 0);
    }

    /**
     * 删除账号荧光棒明细
     */
    @ApiOperation(value = "删除账号荧光棒明细",notes = "删除账号荧光棒明细",response = AjaxResult.class)
    @PreAuthorize("@ss.hasPermi('system:userLightStack:remove')" )
    @Log(title = "账号荧光棒明细" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iUserLightStackService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
